/**
 * AI智能体插件 - API配置管理
 * 
 * 说明：插件不再包含具体的业务API接口，而是提供API配置注入机制
 * 使用方需要在初始化时传入具体的API配置
 */

// 默认API配置（可被外部覆盖）
let apiConfig = {
	// 历史对话消息
	getChatHistoryList: null,
	// 语音识别token
	chatAudioToken: null,
	// 清除对话上下文
	clearChatMessage: null,
	// 创建新对话
	chatOpenNewHistory: null,
	// 常问问题
	chatGuessProblem: null,
// 对话列表
	chatSessionList: null,
	// 智能体列表
	chatTechnologyList: null,
	// 智能体详情
	chatTechnologyDetail: null,
	// 默认智能体
	getDefaultAgent: null,
	// 百度语音识别
	baiduAudioRecognition: null
};

/**
 * 设置API配置
 * @param {Object} config API配置对象
 */
export const setApiConfig = (config) => {
	apiConfig = { ...apiConfig, ...config };
};

/**
 * 获取API配置
 * @returns {Object} 当前API配置
 */
export const getApiConfig = () => {
	return apiConfig;
};

/**
 * 检查API配置是否完整
 * @returns {boolean} 是否所有必需的API都已配置
 */
export const checkApiConfig = () => {
	const requiredApis = [
		'getChatHistoryList',
		'chatOpenNewHistory',
		'chatTechnologyList',
		'getDefaultAgent'
	];
	
	return requiredApis.every(key => typeof apiConfig[key] === 'function');
};

// 向后兼容的API导出（使用配置中的API函数）
	export const getChatHistoryList = (params, config = {}) => {
	if (!apiConfig.getChatHistoryList) {
		throw new Error('getChatHistoryList API not configured. Please call setApiConfig() first.');
	}
	return apiConfig.getChatHistoryList(params, config);
};

export const chatAudioToken = (params, config = {}) => {
	if (!apiConfig.chatAudioToken) {
		throw new Error('chatAudioToken API not configured. Please call setApiConfig() first.');
	}
	return apiConfig.chatAudioToken(params, config);
};

export const clearChatMessage = (params, config = {}) => {
	if (!apiConfig.chatClearMessage) {
		throw new Error('chatClearMessage API not configured. Please call setApiConfig() first.');
	}
	return apiConfig.clearChatMessage(params, config);
};

export const chatOpenNewHistory = (params, config = {}) => {
	if (!apiConfig.chatOpenNewHistory) {
		throw new Error('chatOpenNewHistory API not configured. Please call setApiConfig() first.');
	}
	return apiConfig.chatOpenNewHistory(params, config);
};

export const chatGuessProblem = (params, config = {}) => {
	if (!apiConfig.chatGuessProblem) {
		throw new Error('chatGuessProblem API not configured. Please call setApiConfig() first.');
	}
	return apiConfig.chatGuessProblem(params, config);
};

export const chatSessionList = (params, config = {}) => {
	if (!apiConfig.chatSessionList) {
		throw new Error('chatSessionList API not configured. Please call setApiConfig() first.');
	}
	return apiConfig.chatSessionList(params, config);
};

export const chatTechnologyList = (params, config = {}) => {
	if (!apiConfig.chatTechnologyList) {
		throw new Error('chatTechnologyList API not configured. Please call setApiConfig() first.');
	}
	return apiConfig.chatTechnologyList(params, config);
};

export const chatTechnologyDetail = (params, config = {}) => {
	if (!apiConfig.chatTechnologyDetail) {
		throw new Error('chatTechnologyDetail API not configured. Please call setApiConfig() first.');
	}
	return apiConfig.chatTechnologyDetail(params, config);
};

export const getDefaultAgent = (params, config = {}) => {
	if (!apiConfig.getDefaultAgent) {
		throw new Error('getDefaultAgent API not configured. Please call setApiConfig() first.');
	}
	return apiConfig.getDefaultAgent(params, config);
};

export const baiduAudioRecognition = (params, config = {}) => {
	if (!apiConfig.baiduAudioRecognition) {
		console.warn('baiduAudioRecognition API not configured. This is optional.');
		return Promise.resolve(null);
	}
	return apiConfig.baiduAudioRecognition(params, config);
};